package com.me.videoservice.config;


import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import java.util.List;
import java.util.TimeZone;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

  @Override
  public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.stream().filter(it -> it instanceof MappingJackson2HttpMessageConverter)
        .forEach(it -> {
          ObjectMapper mapper = ((MappingJackson2HttpMessageConverter) it).getObjectMapper();
          mapper.setPropertyNamingStrategy(new SnakeCaseStrategy());
          mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
          mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        });
  }

}
